#!/bin/sh
# -*- coding: utf-8 -*-
#Filename:   replace.sh
#Author:     Yaoyi
#Email:      yaoyi@zzvcom.com
#Date:       2019-06-11 09:01:15
#Desc:       ������������ 

#load common func
source ../source/common/functions.sh
source ../source/common/bussinessfun.sh
#set var
NAME=`basename $0`
dir=`pwd`
if [ -z `cat ${dir}/DIRCONFIG` ]
then
    yaoecho hr "DIRCONFIG has not contents";EchoErr ${LINENO};exit 1
fi
if [ X`ls ${dir}/package` = X ]
then
    yaoecho hr "package directory is null";EchoErr ${LINENO};exit 1
fi
IFS=$'\n'
for conf in `cat ${dir}/DIRCONFIG|grep -v ^#|grep -v "^$"`
do
	[ X"${conf}" = X ] && (yaoecho hr "DIRCONFIG file format error,please check ${dir}/DIRCONFIG";EchoErr ${LINENO};exit 1)
	sed -i '/\[Upgrade\]/a\'${conf}'' `dirname ${dir}`/source/conf/DIRCONFIG.ini
	sed -i '/\[md5_config\]/a\'${conf}'' `dirname ${dir}`/check/conf/check_1.conf
done
for programe in `ls ${dir}/package|grep -v .tgz`
do
	[ X"${programe}" = X ] && (yaoecho hr "Directory:${dir}/package has not updatefile or updatedirectory,please check it";EchoErr ${LINENO};exit 1)
    echo "${programe}=${dir}/package" > `dirname ${dir}`/md5/DIRCONFIG
    cd `dirname ${dir}`/md5
    sh produce.sh
    cd ${dir}/package
    tar zcvf ${programe}.tgz ${programe}
    rm -rf ${programe}
    mv -f ${programe}.tgz `dirname ${dir}`/source/package
    rm -rf `dirname ${dir}`/md5/DIRCONFIG
done

 
